﻿using System.Windows.Forms;
using KillBill.Common.View;
namespace KillBill.Presentation.Common.WindowsForms.View
{
    public class KillBillWinFormView : Form, IKillBillView
    {
        public void ShowConnectionErrorMessage(string module)
        {
           ShowMessage (module,
               "No se ha podido conectar con el servicio. " +
               "Comuniquese con el administrador del sistema",
               MessageOptions.Ok,
               MessageIcon.Error
               );
        }
        public MessageResponse ShowMessage(string message)
        {
            return ConvertToMessageResponse(MessageBox.Show(message));
        }
        public MessageResponse ShowMessage(string title, string message)
        {
            return ConvertToMessageResponse(MessageBox.Show(message, title));
        }
        public MessageResponse ShowMessage(string title, string message, MessageOptions options, MessageIcon icon)
        {
            MessageBoxButtons buttons;
            MessageBoxIcon messageBoxIcon;
            #region MessageButtons
            switch (options)
            {
                case MessageOptions.AbortRetryIgnore:
                    buttons = MessageBoxButtons.AbortRetryIgnore;
                    break;
                case MessageOptions.Ok:
                    buttons = MessageBoxButtons.OK;
                    break;
                case MessageOptions.OkCancel:
                    buttons = MessageBoxButtons.OKCancel;
                    break;
                case MessageOptions.RetryCancel:
                    buttons = MessageBoxButtons.RetryCancel;
                    break;
                case MessageOptions.YesNo:
                    buttons = MessageBoxButtons.YesNo;
                    break;
                default:
                    buttons = MessageBoxButtons.YesNoCancel;
                    break;
            }
            #endregion
            #region MessageIcon
            switch (icon)
            {
                case MessageIcon.Error:
                    messageBoxIcon = MessageBoxIcon.Error;
                    break;
                case MessageIcon.Exclamation:
                    messageBoxIcon = MessageBoxIcon.Exclamation;
                    break;
                case MessageIcon.Hand:
                    messageBoxIcon = MessageBoxIcon.Hand;
                    break;
                case MessageIcon.Information:
                    messageBoxIcon = MessageBoxIcon.Information;
                    break;
                case MessageIcon.None:
                    messageBoxIcon = MessageBoxIcon.None;
                    break;
                case MessageIcon.Question:
                    messageBoxIcon = MessageBoxIcon.Question;
                    break;
                default:
                    messageBoxIcon = MessageBoxIcon.Warning;
                    break;
            }
            #endregion
            return ConvertToMessageResponse(MessageBox.Show(message, title, buttons, messageBoxIcon));
        }
        public MessageResponse ConvertToMessageResponse(DialogResult dialogResult)
        {
            switch (dialogResult)
            {
                case DialogResult.Abort:
                    return MessageResponse.Abort;
                case DialogResult.Cancel:
                    return MessageResponse.Cancel;
                case DialogResult.Ignore:
                    return MessageResponse.Ignore;
                case DialogResult.No:
                    return MessageResponse.No;
                case DialogResult.OK:
                    return MessageResponse.Ok;
                case DialogResult.Retry:
                    return MessageResponse.Retry;
                case DialogResult.Yes:
                    return MessageResponse.Yes;
            }
            return MessageResponse.None;
        }

        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // KillBillWinFormView
            // 
            this.ClientSize = new System.Drawing.Size(310, 262);
            this.Name = "KillBillWinFormView";
            this.ResumeLayout(false);

        }
    }
}
